package cn.suimg.neo4j.repository;

import cn.suimg.neo4j.graph.NeoGraph;
import cn.suimg.neo4j.graph.SingerGraph;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SingerGraphRepository extends Neo4jRepository<SingerGraph, Long> {

    /**
     * 根据歌手ID查询歌手
     * @param singerId
     * @return
     */
    SingerGraph findBySingerId(@Param("singerId") Integer singerId);

    @Query("match (singer:歌手) -[:演唱] -> (songGraph:歌曲) where singer.singerId = {singerId} return distinct count(songGraph)")
    Long checkSingerHasData(@Param("singerId") Integer singerId);


    /**
     * 根据歌手ID查询一起演唱过的关系
     * @param singerId
     * @return
     */
    @Query("match (source:歌手) -[:演唱] -> (targetSong:歌曲) <- [:演唱] - (targetSinger:歌手) where source.singerId = {singerId} return distinct targetSong,targetSinger")
    List<NeoGraph> querySingedSingerAndSongBySingerId(@Param("singerId")Integer singerId);

    /**
     * 查询歌手发布的专辑数量
     * @param singerId
     * @return
     */
    @Query("match (singerGraph:歌手) -[:发布] -> (albumGraph:专辑) where singerGraph.singerId = {singerId} return count(albumGraph)")
    Long countAlbumCount(@Param("singerId") Integer singerId);

}
